<?php
/*
 * template/index.phtml
 */
?>
<?php

use RHX\Helper\RHDateTime;
?>
<?php
$title		 = "Gestion Planning Type";
$this->headTitle($title);
$templates	 = $this->templates;
$codes		 = $this->codes;
?>

<div class="content-head">
    <h3><?php echo $title ?></h3>
    <div class='toolbar'>
        <div class="toggle add" title="ajouter">
            <a class='pl-add' href="#" style="display: block; width: 100%; height: 100%;"></a>
        </div>
    </div>
</div>

<div class="content-body">
    <div class="list-container" id='edition'>
	<table class='table table-striped list-table'>
	    <thead>
		<tr>
		    <td style='text-align: center;'>Num</td>
		    <td style='text-align: center;'>Libellé</td>
		    <td style='text-align: center;'>Site</td>
		    <td style='text-align: center;'>Date de Création</td>
		    <td style='text-align: center;'>Date d'Edition</td>
		    <td></td>
		</tr>
	    </thead>
	    <tbody>
		<?php foreach ($templates as $tpl): ?>
		    <?php $site		 = $tpl->getSite(); ?>
		    <?php
		    $creation	 = new RHDateTime($tpl->creation);
		    $edition	 = new RHDateTime($tpl->edition);
		    ?>
    		<tr>
    		    <td>
    			<a class='pl-edit' data-site='<?php echo $tpl->site_id ?>'  href="<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'edit', 'id'		 => $tpl->template)) ?>">
				<?php echo $tpl->template ?>
    			</a>
    		    </td>
    		    <td>
    			<a class='pl-edit' data-site='<?php echo $tpl->site_id ?>'  href="<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'edit', 'id'		 => $tpl->template)) ?>">
				<?php echo $tpl->libelle ?>
    			</a>
    		    </td>
    		    <td style='text-align: center;'>
    			<a class='pl-edit' data-site='<?php echo $tpl->site_id ?>'  href='<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'edit', 'id'		 => $tpl->template)) ?>'>
				<?php echo $site->libelle; ?>
    			</a>
    		    </td>
    		    <td style='text-align: center;'>
    			<a class='pl-edit' data-site='<?php echo $tpl->site_id ?>'  href='<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'edit', 'id'		 => $tpl->template)) ?>'>
				<?php echo $creation->dateFr(); ?>
    			</a>
    		    </td>
    		    <td style='text-align: center;'>
    			<a class='pl-edit' data-site='<?php echo $tpl->site_id ?>'  href='<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'edit', 'id'		 => $tpl->template)) ?>'>
				<?php echo $edition->dateFr(); ?>
    			</a>
    		    </td>
    		    <td style='text-align: center;'>
    			<a class='pl-edit' data-site='<?php echo $tpl->site_id ?>' href='<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'edit', 'id'		 => $tpl->template)) ?>'>
    			    <img src='<?php echo $this->basePath() . '/img/grh/edit-16x15.png' ?>' alt='Editer' title='Editer'>
    			</a>
    			<a class='pl-delete' data-site='<?php echo $tpl->site_id ?>'  href='<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'erase', 'id'		 => $tpl->template)) ?>'>
    			    <img src='<?php echo $this->basePath() . '/img/grh/delete-16x16.png' ?>' alt='Effacer' title='Effacer'>
    			</a>
    		    </td>
    		</tr>
		<?php endforeach; ?>
	    </tbody>
	</table>
    </div>
</div>

<div id='pl-dialog'></div>

<script type='text/javascript'>
    $(document).ready(function() {
	// Suppression
	$('.pl-delete').click(function(event) {
	    event.preventDefault();
	    conf = confirm("Voulez-vous effacer le planning Type ?");
	    if (conf) {
		href = $(this).attr('href');
		ajax = $.ajax({
		    type: 'post',
		    url: href
		});
		ajax.success(function() {
		    location.reload();
		});
		ajax.error(function() {
		    alert('erreur');
		});
	    }

	    return false;
	});
	// Edition
	$('.pl-edit').click(function(event) {
	    event.preventDefault();
	    var adresse = $(this).attr('href');
	    var site = $(this).attr('data-site');
	    var ajax = $.ajax({
		type: 'post',
		url: adresse,
		data: "&site_id=" + site
	    });
	    ajax.success(function(data) {
		var w = parseInt($('body').css('width'));
		var h = parseInt($('body').css('height'));
		if (h < 700)
		    h = 710;
		$('#pl-dialog').html(data).dialog({
		    width: w - 20,
		    height: h - 10,
		    title: "Edition du Planning Type",
		    autoOpen: true,
		    modal: true,
		    show: {effect: 'fade', duration: 1000},
		    hide: {effect: 'fade', duration: 700}
		});
//		fullScreenLayout();
//		$('#fullScreen').html(data).fadeIn('normal');
	    });
	    ajax.error(function() {
		alert("Une erreur est survenue");
	    });
	});
	// Ajout
	$('.pl-add').click(function(event) {
	    event.preventDefault();
	    var adresse = "<?php echo $this->url('RHX/default', array('controller'	 => 'template', 'action'	 => 'addyesno')) ?>";
	    var ajax = $.ajax({
		type: 'post',
		url: adresse
	    });
	    ajax.success(function(data) {
		var w = 400;
		var h = 500;
		$('#pl-dialog').html(data).dialog({
		    width: w,
		    height: h,
		    title: "Nouveau Planning Type",
		    autoOpen: true,
		    modal: true,
		    show: {effect: 'fade', duration: 1000},
		    hide: {effect: 'fade', duration: 700}
		});
	    });
	    ajax.error(function() {
		alert("Une erreur est survenue");
	    });
	});
    });
    // Masquage et Affichage
    function fullScreenLayout() {
	// masquage
	$('.left-content').fadeOut('slow');
	$('.right-content').fadeOut('slow');
    }
    // Affichage et masquage
    function normalScreenLayout() {
	// Masquage
	$('#fullScreen').fadeOut('fast');
	// Affichage
	$('.left-content').fadeIn('fast');
	$('.right-content').fadeIn('fast');
    }
</script>
